// 需求2：解决接口封装
import request from './request'
// 1.导入vue自带的qs！！
import qs from 'qs'

// baseURL: 'http://192.168.113.249:8081/cms'
// export const JinPinAPI = request.get("/products/recommend")
// /sendSMS

// 需求3：解决导入js文件时，不需要的请求
// export const JinPinAPI = () => request.get("/products/recommend")
export const JinPinAPI1 = () => request.get("/products/recommend")
// 需求4: 设置请求头参数
export const JinPinAPI = () => request.get("/products/recommend",
    //  {
    //     // 请求头配置
    //     headers: {
    //         // 携带token
    //         token: 12345
    //     }
    // }
)

// 请求后台 获取验证码
// params {phone:13544448888}
// 接口：sendSms
// axios.post(url[,data])
// post给后台的参数，需要qs.stringify()转换

export const SendSMSAPI = (params) =>
    // 参考post请求
    // request.post('/sendSMS', params)
    request.post('/sendSMS', qs.stringify(params))

// 携带参数
// console.log(
//     "qs.stringify:",
//     qs.stringify({ phone: "13699998888", name: "zhangsan" })
//     // 解析为：qs.stringify: phone=13699998888&name=zhangsan
// );

export const PhoneReginAPI = (params) =>
    request.post('/phoneRegin',
        qs.stringify(params)
    )
// 微信扫码请求
// /wechatUsers/PCLogin
export const PCLoginAPI = (params) =>
    request.post('/wechatUsers/PCLogin',
        qs.stringify(params)
    )

// /wechatUsers/binding 绑定手机号请求
export const BindingAPI = (params) =>
    request.post('/wechatUsers/binding',
        qs.stringify(params)
    )

// 获取用户信息/shop/userProfiles

export const UserProfilesAPI = () => request.get("/shop/userProfiles")

// 精品推荐 /products/recommend
// 热门兑换 /products/hot
export const RecommendAPI = () => request.get("/products/recommend")
export const HotAPI = () => request.get("/products/hot")
// 详情页 /products/{id}
export const ProductsAPI = (id) => request.get(`/products/${id}`)
// 请求购物车 /shop/carts/add
export const ShopAddAPI = (params) =>
    request.post('/shop/carts/add',
        qs.stringify(params)
    )
// 全部商品/products
export const ProductAllAPI = (obj) => request.get("/products", {
    params: obj
})
// 查看购物车 /shop/carts
export const CartsAPI = () => request.get('/shop/carts')

// 请求删除购物车商品
export const CartDelApi = (params) => request.delete(`/shop/carts?productIds=${params.id}`);
